import { request, ListData, SearchParamsData, WorkDataProps, baseAdminAPI } from '@/service/request'

export interface MonthlyDataProps {
  month: string
  data: {
    count: number
    use: number
  }
}

export async function fetchTemplates(payload: SearchParamsData) {
  const rawData = await request<ListData<WorkDataProps>>(baseAdminAPI + '/template', 'get', payload)
  return rawData.data
}

// ids  '1' 或 '1,2,3'
export async function updatePublic(payload: { ids: string; isPublic: boolean }) {
  await request(baseAdminAPI + '/template/isPublic', 'patch', payload)
}

export async function updateHot(payload: { ids: string; isHot: boolean }) {
  await request(baseAdminAPI + '/template/isHot', 'patch', payload)
}

export async function updateOrderIndex(payload: { ids: string; orderIndex: number }) {
  await request(baseAdminAPI + '/template/orderIndex', 'patch', payload)
}

export async function getCount() {
  const rawData = await request<{ count: number; use: number }>(baseAdminAPI + '/template/getCount', 'get')
  return rawData.data
}

export async function getMonthlyCount() {
  const rawData = await request<MonthlyDataProps[]>(baseAdminAPI + '/template/getMonthlyCount', 'get')
  return rawData.data
}
